﻿using SqlSugar;
using System.Reflection;

namespace PMRC.API.Context
{
    public class DbContext : SqlSugarClient
    {
        public DbContext(ConnectionConfig config) : base(config)
        {
            //CreateDatabaseIfNotExists();
        }

        /// <summary>
        /// 实例化数据库
        /// </summary>
        private void CreateDatabaseIfNotExists()
        {
            // 获取当前命名空间下的所有类类型
            var entitiesNamespace = "PMRC.API.Domain";
            var assembly = Assembly.GetExecutingAssembly();
            var types = assembly.GetTypes().Where(x => x.Namespace == entitiesNamespace).ToArray();
            CodeFirst.InitTables(types);
        }
    }
}
